
package com.yixiu.common.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


/**
 * Producer只是一个接口，需要有对应的实现，并注入到bean容器中
 * 生成验证码配置
 * 报错：No qualifying bean of type 'com.google.code.kaptcha.Producer' available
 */
@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha producer() {
        Properties properties = new Properties();

        /**  下面是一些验证码配置，参考https://blog.csdn.net/baidu_34211956/article/details/83007025
        <prop key="kaptcha.border">yes</prop>
		<prop key="kaptcha.border.color">105,179,90</prop>
		<prop key="kaptcha.textproducer.font.color">blue</prop>
		<prop key="kaptcha.image.width">125</prop>
		<prop key="kaptcha.image.height">45</prop>
		<prop key="kaptcha.textproducer.font.size">45</prop>
		<prop key="kaptcha.session.key">code</prop>
		<prop key="kaptcha.textproducer.char.length">4</prop>
		<prop key="kaptcha.textproducer.font.names">宋体,楷体,微软雅黑</prop>
              **/

        properties.put("kaptcha.border", "yes"); // 加边框，难识别
        properties.put("kaptcha.textproducer.font.color", "105,179,90");  // 边框颜色  "black");
        properties.put("kaptcha.textproducer.char.space", "5");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
